package bb.lanxing.devices.sync;

import bb.lanxing.devices.utils.XZDeviceHelper;
import bb.lanxing.lib.devices.base.DeviceContext;
import bb.lanxing.lib.devices.core.sync.DeviceFile;
import bb.lanxing.lib.devices.core.sync.FitDeviceFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SprintSyncManager extends AbstractGenericDeviceSyncManager {
    public SprintSyncManager(String str) {
        setSprintController(XZDeviceHelper.getSprintController(str));
        init(new SprintFitProcessor(), DeviceContext.getRootDir(9));
    }

    @Override
    public void notifyReadFileList(List<DeviceFile> list) {
        if (list != null && !list.isEmpty()) {
            ArrayList arrayList = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            for (DeviceFile deviceFile : list) {
                if (exists(deviceFile)) {
                    arrayList.add(deviceFile);
                } else {
                    arrayList2.add(deviceFile);
                }
            }
            Comparator<DeviceFile> comparator = new Comparator<DeviceFile>() {
                @Override
                public int compare(DeviceFile deviceFile2, DeviceFile deviceFile3) {
                    int i = 0;
                    int startTime = deviceFile2 instanceof FitDeviceFile ? (int) (((FitDeviceFile) deviceFile2).getStartTime() / 1000) : 0;
                    if (deviceFile3 instanceof FitDeviceFile) {
                        i = (int) (((FitDeviceFile) deviceFile3).getStartTime() / 1000);
                    }
                    return i - startTime;
                }
            };
            Collections.sort(arrayList, comparator);
            Collections.sort(arrayList2, comparator);
            list.clear();
            list.addAll(arrayList2);
            list.addAll(arrayList);
        }
        super.notifyReadFileList(list);
    }
}
